﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using University.Workshop.Model;
using University.Workshop.Presenters.Kardex.Modify;

namespace University.Workshop.Presentation.Kardex.Modify
{
    /// <summary>
    /// Interaction logic for PageSecondStepModifyKardex.xaml
    /// </summary>
    public partial class PageSecondStepModifyKardex : Page,Presenters.Kardex.Modify.ISecondStepForModifyKardex
    {
        private PresenterModifyKardexView pInternal;
        private PresenterSecondStepForModifyKardex pSecondStepModifyKardex;
        public PageSecondStepModifyKardex(PresenterModifyKardexView pExternal)
        {
            InitializeComponent();
            pSecondStepModifyKardex=new PresenterSecondStepForModifyKardex(this);
            this.pInternal = pExternal;
        }

        private void Squaredd_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            pSecondStepModifyKardex.SelectedSquare();
        }

        public void setListAllotmentName(ICollection<Model.Allotment> list)
        {
            Allotmentdd.ItemsSource = list;
        }


        public void setListSquaresAvailable(ICollection<string> squares)
        {
            Squaredd.ItemsSource = squares;
        }

        public bool EnableAllotmentName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                Allotmentdd.IsEnabled = value;
            }
        }

        public string AllotmentName
        {
            get
            {
                return Allotmentdd.Text;
            }
            set
            {
                var objs=((List<Allotment>) Allotmentdd.ItemsSource).Where(x=>x.AllotmentName==value);
                if (objs.Count() != 0)
                    Allotmentdd.SelectedItem = objs.First();

            }
        }

        public string SquareId
        {
            get
            {
                if (Squaredd.SelectedValue != null)
                    return Squaredd.SelectedValue.ToString();
                else
                    return string.Empty;
            }
            set
            {
                if (value == null)
                    Squaredd.SelectedItem=null;
                else if (((List<string>)Squaredd.ItemsSource).Contains(value) && !string.IsNullOrEmpty(value))
                    Squaredd.SelectedValue = value;
            }
        }


        public string PersonId
        {
            get
            {
                return PartnerIdTxt.Text;
            }
            set
            {
                PartnerIdTxt.Text = value;
            }
        }

        public Model.Kardex KardexToModify
        {
            get;
            set;
        }

        public void Update()
        {
            pSecondStepModifyKardex.RefreshSquare();
            pSecondStepModifyKardex.UpdateDataKardex();
        }

        public string SystemMessage
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                pInternal.NotifySystemMessage(value);
            }
        }

        public string ErrorMessage
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                pInternal.NotifyErrorMessage(value);
            }
        }


        public void ChargeDataToBasic()
        {
            pSecondStepModifyKardex.ChargeDataKardex();
        }

        public void GoNextPage()
        {
            pInternal.GoStepTwo();

        }

        public void GoBackPage()
        {
        }


        public int AllotmentNameId
        {
            get
            {
                if (Allotmentdd.SelectedItem == null)
                    return 0;
                return ((Model.Allotment) Allotmentdd.SelectedItem).AllotmentId;
            }
            set
            {
                throw new NotImplementedException();
            }
        }
    }
}
